package com.pan.service.aspect;

import com.pan.common.RedisKeyName;
import com.pan.excep.enume.ErrorCode;
import com.pan.excep.error.ServiceException;
import com.pan.tools.RedisTools;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Aspect
@Component
public class CartAspect {

    @Resource
    private RedisTools redisTools;


    @Pointcut("execution(public com.pan.entity.Result com.pan.service.impl.CartServiceImpl.addCart(java.lang.String,java.lang.Long,java.lang.Integer))")
    public void addCartCut(){}

    @Before("addCartCut()")
    public void checkLogin(JoinPoint joinPoint){
        String userTicket = (String) joinPoint.getArgs()[0];
        Boolean isUser = redisTools.stringRedisTemplate.hasKey(RedisKeyName.USER_NAME+userTicket);
        if (!isUser){
            throw new ServiceException(ErrorCode.NOT_LOGIN);
        }
    }






}
